<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap-theme.min.css"/>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css"/>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/themes/icon.css"/>

<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">
	$(function(){
		$("input[name=renewpsw]").blur(function(){
			$("#error").text("");
			var newpsw = $("input[name=newupsw]").val();
			var renewpsw = $("input[name=renewpsw]").val();
			if(newpsw != renewpsw){
				$("#error").text("两次密码输入不一致");
				$("input[name=newupsw]").val("");
				$("input[name=renewpsw]").val("");
			}
		});
		$("#modifyButton").click(function(){
			var upsw = $("input[name=upsw]").val();
			var newupsw = $("input[name=newupsw]").val();
			var renewpsw = $("input[name=renewpsw]").val();
			if(renewpsw!=""){
				$.ajax({
					type: 'post',
					url: '${pageContext.request.contextPath}/modifyPswAction',
					dataType: 'json',
					data: {"upsw": upsw,"newupsw": newupsw,"renewpsw": renewpsw},
					success: function(data){
						if(data=="1"){
							$("input[name=upsw]").val("");
							$("input[name=newupsw]").val("");
							$("input[name=renewpsw]").val("");
							$.messager.show({
								title:'提示',
								msg:'修改成功',
								timeout:2000,
								showType:'slide'
							});
						}else{
							window.parent.$.messager.alert('','原密码输入错误，请重新登录',"error",function(){
								$.ajax({
									type: 'post',
									url: '${pageContext.request.contextPath}/quitAction',
									dataType: 'text',
									success: function(data){
										if(data=="1"){
											window.parent.location="${pageContext.request.contextPath}/login.jsp";
										}
									}
								})
								
							});				
						}
					}
				});
			}
		});
	});
</script>
<body>
	<div class="container-fluid">
		<div class="row">
			<div class="col-md-6 col-md-offset-3" style="margin-top: 100px">
				<form class="form-horizontal" action="${pageContext.request.contextPath}/modifyPswAction" method="post">
				  <div class="form-group">
				    <label class="col-md-2 control-label">原密码</label>
				    <div class="col-md-10">
				      <input type="password" class="form-control" name="upsw">
				    </div>
				  </div>
				  <div class="form-group">
				    <label class="col-md-2 control-label">新密码</label>
				    <div class="col-md-10">
				      <input type="password" class="form-control" name="newupsw">
				    </div>
				  </div>
				  <div class="form-group">
				    <label class="col-md-2 control-label">再输一遍</label>
				    <div class="col-md-10">
				      <input type="password" class="form-control" name="renewpsw">
				    </div>
				  </div>
				  
				  <div class="form-group">
				    <div class="col-sm-offset-2 col-sm-10" style="text-align: center">
				      <p id="error"></p>
				      <button id="modifyButton" type="button" class="btn btn-default">确定</button>
				    </div>
				  </div>
				</form>
			</div>
		</div>
	</div>
</body>
</html>